/*
 *                        .::::.
 *                      .::::::::.
 *                     :::::::::::
 *                  ..:::::::::::'
 *               '::::::::::::'
 *                 .::::::::::
 *            '::::::::::::::..
 *                 ..::::::::::::.
 *               ``::::::::::::::::
 *                ::::``:::::::::'        .:::.
 *               ::::'   ':::::'       .::::::::.
 *             .::::'      ::::     .:::::::'::::.
 *            .:::'       :::::  .:::::::::' ':::::.
 *           .::'        :::::.:::::::::'      ':::::.
 *          .::'         ::::::::::::::'         ``::::.
 *      ...:::           ::::::::::::'              ``::.
 *     ````':.          ':::::::::'                  ::::..
 *                        '.:::::'                    ':'````..
 *
 * @Author: byx
 * @Date: 2022-12-01 19:35:54
 * @LastEditors: byx
 * @LastEditTime: 2022-12-01 19:40:41
 * @version: 1.0
 * @Descripttion: wwww.byx1024.top
 */
import React, { Component } from 'react'
import { Select } from 'antd'
import { getChannels } from 'api/channel'
export default class Channel extends Component {
  state = {
    // 频道列表数据
    channels: [],
  }

  render() {
    return (
      <Select
        placeholder="请选择文章频道"
        allowClear
        value={this.props.value}
        onChange={this.props.onChange}
        style={{ width: 200 }}
      >
        {this.state.channels.map(item => (
          <Select.Option key={item.id} value={item.id}>
            {item.name}
          </Select.Option>
        ))}
      </Select>
    )
  }

  componentDidMount() {
    this.getChannelList()
  }

  // 获取频道下拉选择数据
  async getChannelList() {
    const res = await getChannels()
    this.setState({
      channels: res.data.channels,
    })
  }
}
